#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 10 13:20:40 2023

@author: liqingsimac
"""

import numpy as np
R1=[0,2,7,np.inf,np.inf,np.inf]
R2=[2,0,4,6,8,np.inf]
R3=[7,4,0,1,3,np.inf]
R4=[np.inf,6,1,0,1,6]
R5=[np.inf,8,3,1,0,3]
R6=[np.inf,np.inf,np.inf,6,3,0]
W=np.array([R1,R2,R3,R4,R5,R6])

A0=W

# A=np.zeros([7,6,6])
# A[0,:,:]=W
# for k in range(1,7):
#     for i in range(6):
#         for j in range(6):
#             A[k,i,j]=np.min([A[k-1,i,j],A[k-1,i,k-1]+A[k-1,k-1,j]])

A1=np.zeros_like(A0)
for i in range(6):
    for j in range(6):
        A1[i,j]=np.min([A0[i,j],A0[i,0]+A0[0,j]])

A2=np.zeros_like(A0)
for i in range(6):
    for j in range(6):
        A2[i,j]=np.min([A1[i,j],A1[i,1]+A1[1,j]])

A3=np.zeros_like(A0)
for i in range(6):
    for j in range(6):
        A3[i,j]=np.min([A2[i,j],A2[i,2]+A2[2,j]])

A4=np.zeros_like(A0)
for i in range(6):
    for j in range(6):
        A4[i,j]=np.min([A3[i,j],A3[i,3]+A3[3,j]])

A5=np.zeros_like(A0)
for i in range(6):
    for j in range(6):
        A5[i,j]=np.min([A4[i,j],A4[i,4]+A4[4,j]])

A6=np.zeros_like(A0)
for i in range(6):
    for j in range(6):
        A6[i,j]=np.min([A5[i,j],A5[i,3]+A5[3,j]])

x=np.max(A6,axis=0)
hospital=np.sum((x==min(x))*range(6))
print(hospital)
##the first question is answered: v=v3

y=np.array([50,40,60,20,70,90])
B=np.dot(A6,y)
C=B==min(B)
school=np.sum(C*range(6))
print(school)
##the second question is answered: v=v4




